﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Linkman_GetCustomLinkmanByType]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Linkman_GetCustomLinkmanByType];
GO
CREATE PROCEDURE [dbo].[sproc_Linkman_GetCustomLinkmanByType]
@typeid int,
@staffid int
/*-------------------------------------------------
功能：按分类得到自定义联系人
参数： 
    @typeid        类别id
    @staffid    用户id


---------------------------------------------------*/
AS
    SELECT UDS_Linkman_CustomLinkman.*,(case UDS_Linkman_CustomLinkman.Gender when 1 then '男' else '女' end) as SexName FROM UDS_Linkman_LinkmanList,UDS_Linkman_CustomLinkman
    WHERE UDS_Linkman_LinkmanList.LinkmanID=UDS_Linkman_CustomLinkman.ID AND UDS_Linkman_LinkmanList.Staff_ID=@staffid AND LinkmanType=3 
    AND UDS_Linkman_LinkmanList.LinkmanID IN (SELECT DISTINCT CustomLinkmanID FROM UDS_Linkman_TypeOfCustomLinkman WHERE TypeID=@typeid)